﻿using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using MindFactorial.LaunchPoint.Runtime;
using MindFactorial.LaunchPoint.Console.Library;

namespace MindFactorial.LaunchPoint.Console
{
    /// <summary>
    /// This class represents the application list at the bottom left
    /// corner of the console
    /// </summary>
	public partial class ControlPanel
	{
        public event LaunchDelegate _applicationLaunching;
		public ControlPanel()
		{
			this.InitializeComponent();
            this.Loaded += new RoutedEventHandler(ControlPanel_Loaded);
			// Insert code required on object creation below this point.
		}

        void ControlPanel_Loaded(object sender, RoutedEventArgs e)
        {
            surfaceAreaD._launching += delegate(string appname)
            {
                //TODO:  log launch request here

                //resend launch event
                if (_applicationLaunching != null)
                {
                    _applicationLaunching(appname);
                }
            };
        }

        internal void HighlightButton()
        {

        }

        internal void RegisterApplication(ConsolePlugIn plugin, bool isactive)
        {
            //register button
            surfaceAreaD.AddButton(plugin.Name, plugin.Label, isactive);
            
        }

        internal void UnRegisterApplication(ConsolePlugIn plugin)
        {
            //remove button from list     
            surfaceAreaD.RemoveButton(plugin.Name);

            //prehaps remove menus

        }

        internal void UnRegisterApplication(string plugin)
        {
            //remove button from list     
            surfaceAreaD.RemoveButton(plugin);

            //prehaps remove menus

        }

        /// <summary>
        /// Launches an application by presenting it's surfaces to the console
        /// </summary>
        /// <param name="plugin"></param>
        internal void LaunchApplication(ConsolePlugIn plugin)
        {
            //attach to area B
            surfaceAreaB.SetPresentationSurface(plugin.ContextAreaSurfacePresenter);
            plugin.ContextAreaSurfacePresenter.SetHost(surfaceAreaB);
        }

      
    }
}